<?php

namespace App\Admin\Actions\GoldRecordAction;

use App\Models\GoldRecord;
use Illuminate\Http\Request;
use App\Supports\Withdraw\Withdrawer;
use App\Services\ApplyGoldRecordBatchExamine\ApplyGoldRecordBatchExamine;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Collection;


class ExamineRecord extends RowAction
{
	public $name = '审核记录';

	public function handle(GoldRecord $model)
	{
		if ($model->isClosed()) {
		    return $this->response()->error('目标订单已关闭');
	    }elseif ($model->isPaid()) {
		    return $this->response()->error('目标订单已支付');
	    }elseif (!$model->goldRecordVoucher()) {
		    return $this->response()->error('目标订单未上传凭证');
		}elseif (!$model->up_gold_record_id) {
		    return $this->response()->error('目标订单没有上级寄售来源');
	    }/*elseif (!$model->goldRecordVoucher()->first()->is_contact) {
		    return $this->response()->error('目标订单未主动联系客服');
	    }  */

	    $unpaidCacheIds = [$model->cache_id];
	    $examineRecord = $model->upGoldRecord->cache_id;
	    $user = $model->upGoldRecord->user;
	   
		app(ApplyGoldRecordBatchExamine::class, [
			'user' => $user,
			'unpaidCacheIds' => $unpaidCacheIds,
			'examineRecord' => $examineRecord,
		])->examine();

		return $this->response()->success('审核成功')->refresh();
	}

	public function dialog()
	{
		$this->confirm('确定审核当前记录，谨慎操作?');
	}
}
